#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define swap(a,b) {int t=a; a=b; b=t;}

struct Line {
	int a, b;
};

bool cmp(Line lhs, Line rhs) {
	return (lhs.b < rhs.b);
}

int N;
vector<Line> L;

int main() {
	scanf("%d", &N);
	for (int i=0; i<N; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a>b) swap(a, b);
		L.push_back((Line){a, b});
	}
	sort(L.begin(), L.end(), cmp);
	int prev = 0;
	int cnt = 1;
	for (int i=1; i<L.size(); i++) {
		if (L[prev].b <= L[i].a) {
			cnt++;
			prev = i;
		}
	}
	printf("%d\n", cnt);
	return 0;
}
